#include <algorithm>
#include <climits>
#include <cstdio>

using namespace std;

int weight[2001];
int dp[1001][2001];

int main(int argc, char const* argv[])
{
    int n, k;
    while (scanf("%d%d\n", &n, &k) != EOF) {
        for (int i = 1; i <= n; i++)
            scanf("%d", &weight[i]);
        sort(weight + 1, weight + 1 + n);
        for (int i = 1; i <= n; i++)
            dp[0][i] = 0;
        for (int i = 1; i <= k; i++) {
            for (int j = 2 * i; j <= n; j++) {
                if (j > 2 * i)
                    dp[i][j] = dp[i][j - 1];
                else // j == 2 * i
                    dp[i][j] = INT_MAX;
                if (dp[i][j] > dp[i - 1][j - 2] + (weight[j] - weight[j - 1]) * (weight[j] - weight[j - 1]))
                    dp[i][j] = dp[i - 1][j - 2] + (weight[j] - weight[j - 1]) * (weight[j] - weight[j - 1]);
            }
        }
        printf("%d\n", dp[k][n]);
    }
    return 0;
}